'''
购买商品，加购物车函数，增加一个检查是否登录的一个装饰器

'''
is_login = False
def login():
    global is_login
    user = input('用户名：')
    pwd = input('密码：')
    if user == 'admin' and pwd == '123':
        is_login = True

def check_login(fun):
    def inner(*args,**kwargs):
        '''加验证登录的功能'''
        while  not is_login:
            login()
        ret = fun(*args,**kwargs)
        return ret
    return inner


@check_login
def add_shopcart(name,price,count,sell):
    print(f'{name}商品，单价为：{price}，数量为：{count}，合计金额￥{price*count*sell}元')
    print('成功加入购物车')

@check_login
def buy_goods(name,price,count):
    print(f'购买{name}商品，单价为：{price}，数量为：{count}，合计金额￥{price*count}元')
    print('购买成功！！')
buy_goods('小米手机redmi k30s',2299,5)

add_shopcart('小米手机redmi k30s',2299,5,.88)

